//
//  WelComeViewController.swift
//  SinaWeibo
//
//  Created by yang on 15/11/12.
//  Copyright © 2015年 yang. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage
class WelComeViewController: UIViewController {

    override func loadView() {
    view = backImage
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        startAnimation()
    }
    //添加动画
    private func startAnimation(){
        self.iconImage.snp_updateConstraints { (make) -> Void in
            make.centerY.equalTo(view.snp_bottom).offset(-screenH+180)
        }
        UIView.animateWithDuration(1.2, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 9.8, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
              UIView.animateWithDuration(0.6, animations: { () -> Void in
                self.label.alpha = 1
                }, completion: { (_) -> Void in
                    NSNotificationCenter.defaultCenter().postNotificationName(AppSwitchRootViewControler, object: nil)
              })
        }
        
    }
    //添加子控件
    private func setupUI(){
        view.addSubview(iconImage)
        view.addSubview(label)
        iconImage.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view)
            make.centerY.equalTo(view.snp_bottom).offset(-180)
            make.width.height.equalTo(90)
        }
        label.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconImage.snp_bottom).offset(20)
            make.centerX.equalTo(view)
        }
        iconImage.sd_setImageWithURL(UserAccountViewModel().userHeadURL, placeholderImage: UIImage(named: "avatar_default_big"))
        label.alpha = 0;
        iconImage.layer.cornerRadius = 45
        iconImage.layer.masksToBounds = true
    }
   private lazy var backImage : UIImageView = UIImageView(image:UIImage(named: "ad_background"))
   private lazy var iconImage : UIImageView = UIImageView()
   private lazy var label : UILabel = UILabel(title: (UserAccountViewModel().userName ?? "") + " 欢迎归来", size: 19, color: UIColor.lightGrayColor())
}
